package com.chinasofti.emp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.chinasofti.manager.service.EmpAttenceService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Creator: <br>
 * Date: <br>
 * Description: <br>
 */
@Controller
@RequestMapping("/emp/attence")
public class EmpAttenceController {
    @Reference
    private EmpAttenceService empAttenceService;

    @GetMapping("/clock")
    public ModelAndView clock(){
        ModelAndView mv = new ModelAndView("attence/clock");
        return mv;
    }

    @PostMapping("/clock")
    public ModelAndView clock(String name){
        ModelAndView mv = new ModelAndView("attence/clock");
        Integer result = empAttenceService.clock(name);
        switch (result){
            case 0:
                mv.addObject("msg", "今天的打卡已结束");
                break;
            case 1:
                mv.addObject("msg", "打卡成功，欢迎上班");
                break;
            case 2:
                mv.addObject("msg", "打卡成功，明天再见");
                break;
        }
        return mv;
    }

}
